/**
 * 
 */
package anyware.desktop.util;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author keke
 * 
 */
public class DesktopUtil {
    private static final Logger LOG = LoggerFactory
                                            .getLogger(DesktopUtil.class);

    public static final ApplicationContext loadContext() {
        final String env = System.getProperty("desktop.env");
        ClassPathXmlApplicationContext ctx = null;
        if (StringUtils.isEmpty(env)) {
            LOG.info("Initializing application context");
            // this is application environment
            ctx = new ClassPathXmlApplicationContext(
                    "meta-inf/applicationContext.xml");
        } else if (env.equals("test")) {
            LOG.info("Initializing test context");
            ctx = new ClassPathXmlApplicationContext("testContext.xml");
        } else if (env.equals("dev")) {
            LOG.info("Initializing development context");
            ctx = new ClassPathXmlApplicationContext("devContext.xml");
        }
        if (ctx != null) {
            ctx.registerShutdownHook();
        }
        return ctx;
    }
}
